<template>
	<view class="home">
		<view class="header">
			<view class="gonggao">
				<u-image width="80rpx" height="36rpx" src="@/static/home/gg.png"></u-image>
				<view class="noticeBar">
					<u-notice-bar @click="noticeDetail" duration="3000" font-size="28" color="#494949"
						:volume-icon="false" mode="vertical" padding="12rpx 12rpx" type="none" :list="noticeData">
					</u-notice-bar>
				</view>
				<view class="more" @click="more">
					<view style="font-size: 28rpx;">更多</view>
					<u-icon name="arrow-right" size="28rpx"></u-icon>
				</view>
			</view>
		</view>

		<view class="title">
			<view class="payqudao">
				<view style="display: flex;align-items: center;">
					<u-image :src="require('@/static/home/huangguan.png')" width="40rpx" height="40rpx"
						mode="aspectFit">
					</u-image>
					<view class="payname">待办服务</view>
				</view>
			</view>
		</view>

		<!-- <view class="card">
			<view class="card_item" v-for="(item,index) in cardData" :key="index" @click="kaitong(item.name)">
				<view class="card_item_l">
					<u-image :src="item.src" width="60rpx" height="60rpx"></u-image>
				</view>
				<view class="card_item_r">
					<view class="name">{{item.name}}</view>
					<view class="tips">{{item.desc}}</view>
				</view>
				<u-tag :text="statusCodeList[item.statusCode]" :type="statusColorList[item.statusCode]" mode="dark"
					size="mini" />
			</view>
		</view> -->

		<view class="shuju">
			<view class="shuju_box boxShow">
				<view class="shuju_tilte">商品统计</view>
				<view class="shuju_content">
					<view class="border shuju_content_item">
						<!-- <view class="shuju_content_item_title">商品统计</view> -->
						<view class="shuju_content_item_content"
							style="display: flex;justify-content: space-between;align-items: center;">
							<view class="shuju_content_item_content-col alignCenter"
								v-for="(item,index) in ProductDatas" :key='index'>
								<view class="shuju_content_item_name">{{item.name}}</view>
								<view class="shuju_content_item_nums">{{item.value}}<text
										style="font-size: 24rpx;">件</text></view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<view class="shuju">
			<view class="shuju_box">
				<view class="shuju_content">
					<view class="shuju_content_item" style="padding:0;">
						<view class="shuju_content_item_title" style="margin-bottom: 30rpx;">
							<view style="display: flex;align-items:flex-end">
								<view>订单数据统计</view>
								<text style="color: #999999;font-size: 24rpx;padding-left:4rpx;">根据时间统计，默认选择当月</text>
							</view>
							<u-image @click="popupShow=true" src="@/static/home/shuaixuan.png" width="29rpx"
								height="29rpx" mode="aspectFit"></u-image>
						</view>
						<view class="shuju_content_item_content">
							<view class="shuju_content_item_content-col" v-for="(item,index) in orderStatisticsData"
								:key="index">
								<view class="shuju_content_item_name">{{item.name}}</view>
								<view class="shuju_content_item_nums">{{item.value}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<u-mask :show="show" :mask-click-able="false">
			<view class="warp">
				<view class="rect">
					<view class="notice-header"></view>
					<view class="notice-content">
						<view class="notice-title">{{noticeDetails.title}}</view>
						<u-parse :html="noticeDetails.content" :tag-style="style"></u-parse>
					</view>
					<view class="notice-footer">
						<u-button shape="circle" type="primary" class="noticeBtn" @click="lejie">我已了解</u-button>
					</view>
				</view>
			</view>
		</u-mask>

		<u-popup v-model="popupShow" mode="bottom" border-radius="14" :safe-area-inset-bottom="true" closeable>
			<view class="slot-content" style="background-color: #FFFFFF;">
				<scroll-view scroll-y="true">
					<view style="height: 40px;text-align: center;font-size: 30rpx;line-height: 40px;">日期筛选</view>
					<view class="sctionContent">
						<view>
							<u-input v-model="form.startDate" type="select" border placeholder="请选择开始日期"
								@click="dateShow = true" />
						</view>
						<view style="padding:0 20rpx;">-</view>
						<view>
							<u-input v-model="form.endDate" type="select" border placeholder="请选择结束日期"
								@click="dateShow = true" />
						</view>
					</view>
				</scroll-view>
				<u-row gutter="16" justify="space-between" style="padding:30rpx 0;">
					<u-col span="6">
						<u-button shape="circle" class="ubtn" type="primary" @click="closeDropdown">确定</u-button>
					</u-col>
					<u-col span="6">
						<u-button shape="circle" type="default" @click="chongzhi">重置</u-button>
					</u-col>
				</u-row>
			</view>
		</u-popup>
		<u-calendar v-model="dateShow" :mode="mode" @change="timeOnchange"></u-calendar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				popupShow: false,
				dateShow: false,
				mode: 'range',
				form: {
					startDate: this.getStartDate(),
					endDate: this.getEndDate()
				},
				show: false,
				noticeDetails: '',
				noticeLists: [],
				noticeData: [],
				style: {
					p: 'font-size:24rpx;color:#646464',
					span: 'font-size: 24rpx;color:#646464'
				},
				//订单数据统计
				orderStatisticsData: [{
					name: '实际订单支付总金额(元)',
					value: 0
				}, {
					name: '订单实际支付糖果(颗)',
					value: 0
				}, {
					name: '待结算金额(元)',
					value: 0
				}, {
					name: '待结算糖果(颗)',
					value: 0
				}],
				//商品数据统计
				ProductDatas: [{
					name: '待编辑商品数',
					value: 0
				}, {
					name: '待审核商品数',
					value: 0
				}, {
					name: '商品审核拒绝数',
					value: 0
				}]
			}
		},
		mounted() {
			//<!-- #ifdef APP-PLUS -->
			this.isAndroid();
			//<!-- #endif -->
			this.getNotice();
			this.getProductDatas();
			this.getDataAnalysis();
		},
		methods: {
			isAndroid() {
				var _this = this;
				uni.getSystemInfo({
					success: (res) => {
						if (res.platform == 'android') {
							_this.$u.http.config.header.platform = res.platform;
							_this.$u.api.version({
								appType: 'KB-MERCHANT-UNDERLYING',
								versionName: plus.runtime.version
							}).then(res => {
								if (res.code == 0) {
									uni.showModal({
										title: '发现新版本' + res.data.versionName,
										content: res.data.updateLog,
										success: (result) => {
											if (result.confirm == true) {
												_this.downLoad(res.data.downloadUrl);
											}
										}
									})
								}
							})
						}

					}
				})
			},
			downLoad(url) {
				uni.showLoading({
					title: '更新中……'
				});
				console.log(url)
				uni.downloadFile({
				    url: url, //仅为示例，并非真实的资源
				    success: (res) => {
				        if (res.statusCode === 200) {
							uni.hideLoading();
							uni.showModal({
								title:'',
								content:'更新成功，确定现在重启吗？',
								confirmText: '重启',
								confirmColor: '#EE8F57',
								success: function(result) {
									if (result.confirm == true) {
										plus.runtime.install(res.tempFilePath,{
											force:true
										},function(){
											utils.showToast('更新成功，重启中');
											plus.runtime.restart();
										})
									}
								}
							})
				        }
				    }
				});
			},
			//获取开始时间
			getStartDate() {
				let date = new Date();
				let startDate = new Date(date.getFullYear(), date.getMonth(), 1);
				let year = startDate.getFullYear();
				let month = startDate.getMonth() + 1 < 10 ? '0' + (startDate.getMonth() + 1) : startDate.getMonth() + 1;
				let day = startDate.getDate() < 10 ? '0' + startDate.getDate() : startDate.getDate();
				return year + '-' + month + '-' + day;
			},
			//获取结束时间
			getEndDate() {
				let date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
				let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
				return year + '-' + month + '-' + day;
			},
			//获取订单数据统计
			getDataAnalysis() {
				this.$u.offlineApi.dataAnalysis(this.form).then(res => {
					if (res.code == 0) {
						this.orderStatisticsData[0].value = res.data.actualPayAmount == null ? 0 : res.data
							.actualPayAmount; //实际支付金额
						this.orderStatisticsData[1].value = res.data.actualPaySweet == null ? 0 : res.data
							.actualPaySweet; //实际支付糖果
						this.orderStatisticsData[2].value = res.data.unsettledAmount == null ? 0 : res.data
							.unsettledAmount; //待结算金额
						this.orderStatisticsData[3].value = res.data.unsettledSweet == null ? 0 : res.data
							.unsettledSweet; //待结算糖果
					} else {
						this.orderStatisticsData = [{
							name: '实际订单支付总金额(元)',
							value: 0
						}, {
							name: '订单实际支付糖果(颗)',
							value: 0
						}, {
							name: '待结算金额(元)',
							value: 0
						}, {
							name: '待结算糖果(颗)',
							value: 0
						}];
						this.$message.error(res.msg);
					}
				})
			},
			//商品数据统计
			getProductDatas() {
				this.$u.offlineApi.foodStatistics().then(res => {
					if (res.code == 0) {
						this.ProductDatas[0].value = res.data.edited;
						this.ProductDatas[1].value = res.data.examine;
						this.ProductDatas[2].value = res.data.refuse;
					} else {
						this.ProductDatas = [{
							name: '待编辑商品数',
							value: 0
						}, {
							name: '待审核商品数',
							value: 0
						}, {
							name: '商品审核拒绝数',
							value: 0
						}]
					}
				})
			},
			//获取公告列表
			getNotice() {
				this.$u.offlineApi.noticeList({
					type: 2
				}).then(res => {
					if (res.code == 0) {
						this.noticeLists = res.data;
						res.data.forEach(item => {
							this.noticeData.push(item.title)
						});
					}
				});
			},
			//公告详情
			noticeDetail(index) {
				this.noticeDetails = this.noticeLists[index];
				this.show = true;
			},
			//我已了解
			lejie() {
				this.show = false;
			},
			//跳转公告列表页面
			more() {
				uni.navigateTo({
					url: '/pages/offline/home/noticeList'
				})
			},
			//开通支付
			kaitong(name) {
				this.$u.toast('敬请期待......');
			},
			closeDropdown() {
				this.getDataAnalysis();
				this.popupShow = false;
			},
			chongzhi() {
				this.form.startDate = '';
				this.form.endDate = '';
			},
			timeOnchange(e) {
				this.form.startDate = e.startDate;
				this.form.endDate = e.endDate;
			},

		}
	}
</script>

<style scoped lang="scss">
	.slot-content {
		padding: 20rpx 30rpx;
	}

	.sctionContent {
		display: flex;
		align-items: center;
		padding: 30rpx 0;
	}

	.title {
		padding: 0 30rpx;

		.payqudao {
			background-color: #ffffff;
			width: 690rpx;
			height: 65rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			border-top-left-radius: 20rpx;
			border-top-right-radius: 20rpx;
			font-size: 30rpx;

			.payname {
				color: #313134;
				font-size: 32rpx;
				font-weight: bold;
				padding-left: 10rpx;
				width: 190rpx;
			}
		}
	}

	.header {
		background-image: url(@/static/home/bg.png);
		background-repeat: no-repeat;
		background-size: 100% 100%;
		width: 100%;
		height: 480rpx;
		display: flex;
		align-items: flex-end;
		justify-content: center;

		.gonggao {
			background-color: #ffffff;
			border-radius: 20rpx 20rpx 0 0;
			height: 76rpx;
			width: 95%;
			padding: 0 20rpx;
			overflow: hidden;
			display: flex;
			align-items: center;
			justify-content: space-around;

			.noticeBar {
				flex: 1;
			}

			.more {
				font-size: 28rpx;
				color: #999999;
				display: flex;
				align-items: center;
			}
		}
	}

	.card {
		padding: 30rpx 30rpx 20rpx 30rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.card_item {
		border-radius: 5rpx;
		width: 333rpx;
		height: 134rpx;
		box-shadow: 0rpx 0rpx 12rpx 0rpx rgba(207, 207, 207, 0.49);
		display: flex;
		align-items: center;
		justify-content: center;
		position: relative;

		.card_item_l {
			margin-right: 20rpx;
		}

		.name {
			font-size: 28rpx;
		}

		.tips {
			font-size: 24rpx;
			color: #CFCFCF;
			margin-top: 10rpx;
		}

		.u-tag {
			position: absolute;
			right: 0;
			top: -18rpx;
		}
	}

	.warp {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 100%;

		.rect {
			background: #FFFFFF;
			box-shadow: 2rpx 6rpx 51rpx 0px rgba(55, 127, 166, 0.3);
			border-radius: 20rpx;
			width: 629rpx;

			.notice-header {
				width: 629rpx;
				height: 259rpx;
				background-image: url(@/static/home/noticeDetailBg.png);
				background-repeat: no-repeat;
				background-size: 100% 100%;

			}

			.notice-content {
				padding: 30rpx;

				.notice-title {
					font-size: 30rpx;
					font-weight: 500;
					color: #000;
					text-align: center;
					margin-bottom: 35rpx;
				}
			}

			.notice-footer {
				padding: 30rpx;

				.noticeBtn {
					background: #1F6ECF;
					box-shadow: 0px 12rpx 16rpx 0px rgba(28, 100, 224, 0.32);
					border-radius: 37rpx;
					font-size: 28rpx;
				}
			}
		}
	}


	.boxShow {
		box-shadow: 0px 0px 8rpx 2rpx rgba(157, 158, 160, 0.35);
	}

	.shuju {
		padding: 10rpx 30rpx 30rpx;

		.shuju_box {
			background: #FFFFFF;
			border-radius: 20rpx;
			overflow: hidden;

			.shuju_tilte {
				background-color: #E6EDFC;
				color: #3D87FC;
				font-size: 32rpx;
				padding: 20rpx 0;
				display: flex;
				align-items: center;
				justify-content: center;
			}

			.shuju_content {
				.border {
					border-bottom: 1px solid #E0DFDF;
				}

				.shuju_content_item {
					padding: 30rpx;

					.shuju_content_item_title {
						font-size: 32rpx;
						color: #000;
						font-weight: bold;
						display: flex;
						align-items: center;
						justify-content: space-between;
					}

					.shuju_content_item_content {
						.alignCenter {
							text-align: center !important;
							flex-direction: column !important;
						}

						.shuju_content_item_content-col {
							display: flex;
							justify-content: space-between;
							align-items: center;

							.shuju_content_item_name {
								padding-top: 30rpx;
								font-size: 28rpx;
								color: #000000;
								padding-bottom: 16rpx;
							}

							.shuju_content_item_nums {
								font-size: 38rpx;
								color: #D93C43;
							}
						}

					}
				}
			}
		}


	}
</style>
